<?php

/**
 * PHP Captcha Widget
 *
 * @package    sfPHPCaptchaPlugin
 * @subpackage form
 * @author     Sven Wappler <info@wapplersystems.de>
 */
class sfWidgetFormMyCaptcha extends sfWidgetForm {

    protected function configure($options = array(), $attributes = array()) {

    }

    public function render($name, $value = null, $attributes = array(), $errors = array()) {

        $this->use_stylesheet();
        $culture = sfContext::getInstance()->getUser()->getCulture();

        sfContext::getInstance()->getConfiguration()->loadHelpers('Asset','Url','I18n');


        $img_src            = url_for('@securimage_show').'?sid='.md5(time()) ;
        $refresh_image_path = image_path('/sfMyCaptchaPlugin/images/refresh.gif');
        $swf_path           = image_path('/sfMyCaptchaPlugin/images/securimage_play.swf').'?audio='.url_for('@securimage_play');
        $img_id             = md5($name).'_siimage';
        $msg_refresh        = __('Refresh Image');
        $msg_code           = sfConfig::get('app_sfMyCaptcha_code_text',__('Code'));
        $input_width        = sfConfig::get('app_sfMyCaptcha_width',250)+4;
        $sound_display      = sfConfig::get('app_sfMyCaptcha_enable_sound',true) ? 'block' : 'none';
        $refresh_display      = sfConfig::get('app_sfMyCaptcha_enable_refresh',true) ? 'block' : 'none';

        $html = <<<EOF
<table class="my-cap-cont" align="center">
<tr>
    <td class="my-cap-img">
        <img id="{$img_id}" src="{$img_src}" />
    </td>
    <td valign="top" class="my-cap-helpers" >
        <span style="display:{$sound_display}">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
			    <param name="allowScriptAccess" value="sameDomain" />
			    <param name="allowFullScreen" value="false" />
			    <param name="movie" value="{$swf_path}&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" />
			    <param name="quality" value="high" />
			
			    <param name="bgcolor" value="#ffffff" />
			    <embed src="{$swf_path}&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
			  </object>
        </span>
        <br />
        <span style="display:{$refresh_display}">
        <a tabindex="-1" href="javascript:;" title="{$msg_refresh}" onclick="document.getElementById('{$img_id}').src = '{$img_src}&sid2=' + Math.random(); return false"><img src="{$refresh_image_path}" alt="{$msg_refresh}" border="0" onclick="this.blur()" align="bottom" /></a>
        </span>
     </td>
</tr>
<tr>
    <td class="my-cap-code">
        <label>{$msg_code}</label><span class="requierd">*</span><br />
        <input type="text" name="{$name}" size="12" autocomplete="off" style="width:{$input_width}px !important" />
    </td>
</tr>
</table>
EOF;

        return $html;

    }


    protected function use_stylesheet(){
       sfContext::getInstance()->getConfiguration()->loadHelpers('Asset');
       use_stylesheet('/sfMyCaptchaPlugin/css/main.css');
    }

}
